// pages/index/notice-list/notice-list.js
const app = getApp();
Page({
  data: {
    isNull: false,
    url: app.globalData.requestUrl,
    courses: []
  },
  onLoad() {
    this.category = app.globalData.category;
    this.loadData();
  },
  goNotify(e) {
    console.log(e.currentTarget.dataset.item);
    wx.navigateTo({
      url: '../notify/notify?image=' + e.currentTarget.dataset.item.image + '&content=' + e.currentTarget.dataset.item.title + '&title=通知',
    })
  },
  loadData() {
    const that = this;
    app.request('/api/question/notice', {category_id: this.category.id, type: 2}).then(res => {
      console.log(res.data)
      if (res.data.code !== 1) {
        wx.showToast({
          title: '服务器错误',
          icon: 'none'
        })
        return;
      }
      that.setData({
        courses: res.data.data,
        isNull: res.data.data.length === 0
      })
    }).catch(err => {
      console.error(err);
    })
  }
});
